﻿//===============================================================================
//	GameHostManager.h
//	服务器组主机设置
//===============================================================================

#pragma once

#include <string>
#include "../../3rd/libjson/json.h"
#include "common_singleton.h"

class GameHostManager : public common::CSingleton< GameHostManager >
{
private:
	Json::Value m_game_host;
	int32_t m_zone_id;  // 服务器分区id, 表示独立的服务器(可能具有不同的开服时间)
	int32_t m_area_id;  // 服务器分区分服id, 对应Lua的 SERVER_AREA_ID
	int32_t m_host_id;  // game_id (HostsConfig中与ip:port关联的id, Lua保存在GAME_HOST_ID)
	int32_t m_db_host_id;
	int32_t m_central_host_id;
	int32_t m_chat_host_id;
	int32_t m_map_host_id;
	int32_t m_loginqueue; // 登录排队尺寸(0=不排队)
public:
	GameHostManager(void);
	~GameHostManager(void);

	uint32_t GetServerZoneId(void);
	uint32_t GetServerAreaId(void);
	uint32_t GetHostId(void);

	uint32_t GetDatabaseServerId(void);
	uint32_t GetCenterServerId(void);
	uint32_t GetChatServerId(void);
	uint32_t GetMapServerId(void);
	uint32_t GetLoginqueue(void);


	int32_t initialize(uint32_t hostId=1);

public:
	std::string GetHostKey(void);

	uint16_t GetGameHostApposite();

	uint16_t GetGameHostListenPort(uint32_t hostId=0);
	std::string GetGameHostIp(uint32_t hostId = 0);

	uint16_t GetCenterHostListenPort(void);
	std::string GetCenterHostIp(void);

	uint16_t GetDatabaseHostListenPort(void);
	std::string GetDatabaseHostIp(void);

	uint16_t GetChatHostListenPort(void);
	std::string GetChatHostIp(void);

	uint16_t GetMapHostListenPort(void);
	std::string GetMapHostIp(void);
	int32_t GetMapTraceLevel(void);
	int32_t GetMapId(void);

	uint16_t GetRankHostListenPort(void);
	std::string GetRankHostIp(void);

	uint16_t GetLoginHostListenPort(void);
	std::string GetLoginHostIp(void);

	uint16_t GetProxyHostListenPort(void);
	std::string GetProxyHostIp(void);

	uint16_t GetWorldProxyHostListenPort(void);
	std::string GetWorldProxyHostIp(void);

	uint16_t GetPlatformProxyHostListenPort(void);
	std::string GetPlatformProxyHostIp(void);

	uint16_t GetGateHostListenPort(void);
	std::string GetGateHostIp(void);

	std::string GetGameDBIP();
	std::string GetGameDBProt();
	std::string GetGameDBUser();
	std::string GetGameDBPwd();
	std::string GetGameDBName();

	std::string GetAccountDBIP();
	std::string GetAccountDBProt();
	std::string GetAccountDBUser();
	std::string GetAccountDBPwd();
	std::string GetAccountDBName();

public:
	void SetMapConnectInfo(std::string& ip, int32_t port = 5684);
};